///////////////////////////////////////////////////////////////////
// Student name:Jon Hersack and Caleb Reinking
// Course: COSC 3403
// Assignment: #7 - Initial Software Construction
// File name:Deck.java
// Purpose: Provides singleton access to deck, which allows classes
//          to get cards
// Assumptions:none known
// Limitations:Deck does not shuffle cards well at this point. A good algorithm
//             needs to be worked out for this action.
// Development Computer:Intel core2 duo 2.67Ghz
// Operating System: windows
// Integrated Development Environment (IDE): netbeans 6.5
// Compiler: Javac: java 1.6.0_13
///////////////////////////////////////////////////////////////////


import java.util.*;
//singleton design based on
//http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html
public class Table
{
    private static Table instance = null;

    Vector<Pile>[] teamPiles = new Vector[2];

    //first index is team number, second is type
    Boolean[][] safetyArea = new Boolean[2][4];
    //order:ROW, DA, PP, ET
    Boolean[][] hazardStatus = new Boolean[2][5];
    //order: stop, speedLimit, out of gas, flattire, accident
    int[] twoHundredsLeft = new int [2];
    //store number of twohundreds left for each team

   //###########################################
   private Table() {


        teamPiles[0] = new Vector<Pile>(2);
        teamPiles[0].add(new Pile());
        teamPiles[0].add(new Pile());

        teamPiles[1] = new Vector<Pile>(2);
        teamPiles[1].add(new Pile());
        teamPiles[1].add(new Pile());

        twoHundredsLeft[0] =2;
        twoHundredsLeft[1] =2;

        resetSafety(0);
        resetHazards(0);
        resetSafety(1);
        resetHazards(1);

   }//end constructor
   
   public static Table getInstanceOf() {
      if(instance == null) {
         instance = new Table();
      }
      return instance;
   }

//##################################################################
   Boolean[] getSafetyArea(int team )
   {
    return safetyArea[team];
   }

   
 //##################################################################
    Boolean[] getHazardStatus(int team )
   {
    return hazardStatus[team];
   }


   //##################################################################
   void setSafetyArea(int team , Boolean Safety[] )
   {
    safetyArea[team]= Safety;
   }


 //##################################################################
    void setHazardStatus(int team , Boolean Status[] )
   {
    hazardStatus[team] = Status;
   }

//#################################################################
   void playOnPile(int team, Card card)
    {

            switch(card.getTypeID())
            {
                case 6:
                      teamPiles[team].elementAt(1).playCard(card);
                      break;
                case 7:
                      teamPiles[team].elementAt(1).playCard(card);
                      break;
                case 8:
                      teamPiles[team].elementAt(1).playCard(card);
                      break;
                case 10: // card goes on other team's battle pile
                      teamPiles[team].elementAt(1).playCard(card);
                      break;
                case 9: // card goes on other team's speed pile
                    teamPiles[team].elementAt(0).playCard(card);
                         break;
                case 11://gas
                    //hazard order: stop, speedLimit, out of gas, flattire, accident
                    teamPiles[team].elementAt(1).playCard(card);
                        break;
                case 12://tire
                    teamPiles[team].elementAt(1).playCard(card);
                        break;
                case 13://repair
                    teamPiles[team].elementAt(1).playCard(card);
                        break;
                case 15://roll
                    teamPiles[team].elementAt(1).playCard(card);
                        break;
                case 14://limit
                    teamPiles[team].elementAt(0).playCard(card);
                        break;
                default: break;
            }//end switch
        
    }// end playOnPile



   //#########################################################33
    void resetSafety(int teamID)
    {
        for( int i = 0 ; i < safetyArea[0].length ; i++ )
        {
        safetyArea[teamID][i] = false;
        }

    }//end resetSafety


       //#########################################################33
    void resetHazards(int teamID)
    {
        for( int i = 0 ; i < hazardStatus[0].length ; i++ )
        {
            hazardStatus[teamID][i] = false;
        }
            hazardStatus[teamID][0]=true;//set stop to true so we need a roll to play

    }//end rsetHazards


    //#################################
    public static void main(String [ ] args)
    {
        Deck myDeck = Deck.getInstanceOf();
        
    }// end test main


}//end class Deck


